dac24 2.2.0
Loading...
Searching...
No Matches
dac24.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef DAC24_H
29#define DAC24_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
59
64
69
74#define DAC24_REG_POWER_DOWN_100K 0x00
75#define DAC24_REG_AO1_DATA_OUT 0x01
76#define DAC24_REG_AO2_DATA_OUT 0x02
77#define DAC24_REG_AO3_DATA_OUT 0x03
78#define DAC24_REG_ALL_CH_DATA_OUT 0x07
79#define DAC24_REG_POWER_DOWN_2_5K 0x08
80#define DAC24_REG_AO1_DATA 0x09
81#define DAC24_REG_AO2_DATA 0x0A
82#define DAC24_REG_AO3_DATA 0x0B
83#define DAC24_REG_POWER_DOWN_HIZ 0x0F
84 // dac24_reg
86
91
96
101#define DAC24_CHANNEL_ALL 0
102#define DAC24_CHANNEL_1 1
103#define DAC24_CHANNEL_2 2
104#define DAC24_CHANNEL_3 3
105
110#define DAC24_POWER_DOWN_HIZ 0
111#define DAC24_POWER_DOWN_2_5K 1
112#define DAC24_POWER_DOWN_100K 2
113
118#define DAC24_DAC_VALUE_MIN 0x00
119#define DAC24_DAC_VALUE_MID 0x80
120#define DAC24_DAC_VALUE_MAX 0xFF
121
126#define DAC24_VCC_3V3 3300
127#define DAC24_VCC_5V 5000
128#define DAC24_VCC_LEVEL DAC24_VCC_3V3
129
138#define DAC24_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
139#define DAC24_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
140 // dac24_set
142
147
152
157#define DAC24_MAP_MIKROBUS( cfg, mikrobus ) \
158 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
159 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
160 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
161 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
162 // dac24_map // dac24
165
170typedef struct
171{
172 // Modules
173 spi_master_t spi;
174
175 pin_name_t chip_select;
176
177} dac24_t;
178
183typedef struct
184{
185 // Communication gpio pins
186 pin_name_t miso;
187 pin_name_t mosi;
188 pin_name_t sck;
189 pin_name_t cs;
190
191 // static variable
192 uint32_t spi_speed;
193 spi_master_mode_t spi_mode;
194 spi_master_chip_select_polarity_t cs_polarity;
195
197
202typedef enum
203{
206
208
214
225
239err_t dac24_init ( dac24_t *ctx, dac24_cfg_t *cfg );
240
253err_t dac24_write_reg ( dac24_t *ctx, uint8_t reg, uint8_t data_in );
254
266err_t dac24_set_power_down ( dac24_t *ctx, uint8_t pwr );
267
280err_t dac24_set_dac_value ( dac24_t *ctx, uint8_t channel, uint8_t value );
281
295err_t dac24_set_dac_voltage ( dac24_t *ctx, uint8_t channel, uint16_t voltage_mv );
296
297#ifdef __cplusplus
298}
299#endif
300#endif // DAC24_H
301 // dac24
303
304// ------------------------------------------------------------------------ END
dac24_return_value_t
DAC 24 Click return value data.
Definition dac24.h:203
@ DAC24_ERROR
Definition dac24.h:205
@ DAC24_OK
Definition dac24.h:204
err_t dac24_set_power_down(dac24_t *ctx, uint8_t pwr)
DAC 24 set power down function.
err_t dac24_write_reg(dac24_t *ctx, uint8_t reg, uint8_t data_in)
DAC 24 write register function.
err_t dac24_init(dac24_t *ctx, dac24_cfg_t *cfg)
DAC 24 initialization function.
err_t dac24_set_dac_value(dac24_t *ctx, uint8_t channel, uint8_t value)
DAC 24 set DAC value function.
void dac24_cfg_setup(dac24_cfg_t *cfg)
DAC 24 configuration object setup function.
err_t dac24_set_dac_voltage(dac24_t *ctx, uint8_t channel, uint16_t voltage_mv)
DAC 24 set DAC voltage function.
This file contains SPI specific macros, functions, etc.
DAC 24 Click configuration object.
Definition dac24.h:184
spi_master_chip_select_polarity_t cs_polarity
Definition dac24.h:194
pin_name_t sck
Definition dac24.h:188
spi_master_mode_t spi_mode
Definition dac24.h:193
pin_name_t mosi
Definition dac24.h:187
uint32_t spi_speed
Definition dac24.h:192
pin_name_t miso
Definition dac24.h:186
pin_name_t cs
Definition dac24.h:189
DAC 24 Click context object.
Definition dac24.h:171
spi_master_t spi
Definition dac24.h:173
pin_name_t chip_select
Definition dac24.h:175